package canss.webservice.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import weblogic.application.utils.XMLWriter;
import canss.supports.basic;
import canss.webservice.service.PortalIntraWebServiceControl;
import canss.webservice.service.PortalIntraWebServiceControlBean;
import canss.webservice.service.PortalIntraWebService_EventLogSerialized;

public class svtOPAdminEventLog extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet
{
	private static final long serialVersionUID = 5568599094711585771L;

	public svtOPAdminEventLog()
	{
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doPost(request, response);
	}

	PortalIntraWebServiceControl control; 
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();

		String _notxml = request.getParameter("_notxml");
		String _mid = request.getParameter("_mid");

		if (_notxml != null)
		{// in html
			out.write("doesn't support raw html.<br/>");

		} else
		{
			out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
			XMLWriter writer = new XMLWriter(out);

			
			writer.addElement("canss");
			writer.addElement("canssEvent_eventGroup");
			if( !basic.isEmpty(_mid) )
			{
				control = (control == null) ? new PortalIntraWebServiceControlBean() : control;
				PortalIntraWebService_EventLogSerialized[] eventlog = control.getEventLogByMID(_mid);
				if (eventlog != null && eventlog.length > 0)
				{
					long i=1;
					for (PortalIntraWebService_EventLogSerialized item : eventlog)
					{
						writer.addElement("canssEvent_eventDescription");
							writer.addElement("index", String.valueOf(i++));
							writer.addElement("canssModule_mid", item.getCanssModule_Mid());
							writer.addElement("canssModule_name", item.getCanssModule_Name());
							writer.addElement("canssEvent_EventID", item.getCanssEvent_EventID().toString());
							writer.addElement("canssEvent_EventName", item.getCanssEvent_EventName());
							writer.addElement("canssEvent_EventSeqnum", item.getCanssEvent_EventSeqnum().toString());
							writer.addElement("canssEvent_Timestamp", item.getCanssEvent_Timestamp());
						writer.closeElement();
					}
				}
			}
			writer.closeElement();
			writer.finish();
		}
	}
}